﻿Imports System.Data.OleDb

Public Class rssView
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try


            If (Not Page.IsPostBack) Then
                If (Request.QueryString("type") <> Nothing) Then
                    Dim type As String = Request.QueryString("type")
                    If (type = "latestQuizzes") Then
                        pnlQuiz.Visible = True
                        pnlComments.Visible = False
                        Dim getLatestQuizes As QuizManagement = New QuizManagement()
                        Dim dr As OleDbDataReader = getLatestQuizes.SelectQuizzesLatest()

                        rptQuizzes.DataSource = dr
                        rptQuizzes.DataBind()
                    ElseIf (type = "latestQuizzesTeacher") Then
                        pnlQuiz.Visible = True
                        pnlComments.Visible = False
                        Dim getLatestQuizesTeachers As QuizManagement = New QuizManagement()
                        Dim dr As OleDbDataReader = getLatestQuizesTeachers.SelectQuizzesLatestByTeacherId(Convert.ToInt32(Request.QueryString("teacherId")))

                        rptQuizzes.DataSource = dr
                        rptQuizzes.DataBind()
                    ElseIf (type = "latestComments") Then
                        pnlQuiz.Visible = False
                        pnlComments.Visible = True

                        Dim getLatestComments As CommentsManagement = New CommentsManagement()
                        Dim dr As OleDbDataReader = getLatestComments.SelectCommentVisibleDesc()

                        rptComments.DataSource = dr
                        rptComments.DataBind()

                    End If
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Function getTitle()
        Try

            Dim type As String = Request.QueryString("type")
            If (type = "latestQuizzes") Then
                Return "Latest Quizzes"
            ElseIf (type = "latestQuizzesTeacher") Then
                Return "Latest Quizzes By Teacher"
            ElseIf (type = "latestComments") Then
                Return "Latest Approved Comments"
            Else

                Return ""
            End If


        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Protected Function getDescription()
        Try

            Dim type As String = Request.QueryString("type")
            If (type = "latestQuizzes") Then
                Return "Latest quizzes generated on the interactive quiz game"
            ElseIf (type = "latestQuizzesTeacher") Then
                Return "Latest quizzes by teacher generated on the interactive quiz game"
            ElseIf (type = "latestComments") Then
                Return "Latest approved comments generated on the interactive quiz game"
            Else
                Return ""
            End If

        Catch ex As Exception
            Return Nothing
        End Try
    End Function



    Protected Function GetPicture(ByVal input As Object)
        Try

            Dim data As String = input.ToString()
            Dim path As String = Request.Url.AbsoluteUri

            Dim type As String = Request.QueryString("type")

            If (type = "latestQuizzes") Then
                path = path.Replace("rssView.aspx?type=latestQuizzes", data)
            ElseIf (type = "latestQuizzesTeacher") Then
                path = path.Replace("rssView.aspx?type=latestQuizzesTeacher&teacherId=" + Request.QueryString("teacherId").ToString(), data)

            End If


            Return FormatForXML(path)

        Catch ex As Exception
            Return Nothing
        End Try
    End Function


    Protected Function GetUser(ByVal input As Object)
        Try

        
        Dim getNameUser As ProfilesManagement = New ProfilesManagement()
        Dim dr As OleDbDataReader = getNameUser.SelectProfileByUserID(Convert.ToInt32(input))

        Dim name As String = ""

        If dr.HasRows Then
            dr.Read()
            If Not IsDBNull(dr("ProfileName")) Then name = (dr("ProfileName"))
            name = name + " "
            If Not IsDBNull(dr("ProfileSurname")) Then name = name + (dr("ProfileSurname"))
        End If

        Return FormatForXML(name)
        Catch ex As Exception
            Return Nothing
        End Try

    End Function

    Protected Function GetLink(ByVal input As Object)
        Try


            Dim data As String = input.ToString()
            Dim path As String = Request.Url.AbsoluteUri

            Dim type As String = Request.QueryString("type")

            If (type = "latestQuizzes") Then
                path = path.Replace("rssView.aspx?type=latestQuizzes", "QuizOverview.aspx?quizId=" + data)
            ElseIf (type = "latestQuizzesTeacher") Then
                path = path.Replace("rssView.aspx?type=latestQuizzesTeacher&teacherId=" + Request.QueryString("teacherId").ToString(), "QuizOverview.aspx?quizId=" + data)
            ElseIf (type = "latestComments") Then
                path = path.Replace("rssView.aspx?type=latestComments", "QuizOverview.aspx?quizId=" + data)
            End If

            Return FormatForXML(path)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Protected Function FormatForXML(ByVal input As Object)
        Try

        
        Dim data As String = input.ToString()
        data = data.Replace("&", "&amp;")
        data = data.Replace("""", "&quot;")
        data = data.Replace("'", "&apos;")
        data = data.Replace("<", "&lt;")
        data = data.Replace(">", "&gt;")

        Return data

        Catch ex As Exception
            Return Nothing
        End Try
    End Function

End Class